<?php 
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";   

//
//'****************************************
//' N I V E L    1
//'****************************************

$strSql="select * from solotb_nivel1 order by des";

SoloFun_ExecSql ($strSql,$arrData);

if ($_REQUEST["CmbEmpresa"]!="")
    $strid1=$_REQUEST["CmbEmpresa"];
else
    $strid1=$arrData[0][0];

//****************************************
// N I V E L    2
//****************************************

$strSql="select * from solotb_nivel2";
$strSql .= " where id1=" . $strid1;
$strSql .= " order by des";
SoloFun_ExecSql ($strSql,$arrData2);
if (empty($arrData2[0][1]))
    $bEOF2 = true;

//'****************************************
//' N I V E L    3
//'****************************************


switch ($_REQUEST["opc"]) {
    case 1:
//Empresa
        $strid2=$arrData2[0][1];
        break;
    case 2:
//Categoria 
        $strid2=$_REQUEST["CmbCategoria"];
        break;
    default:
        $strid2=$arrData2[0][1];
        break;
}

$strSql="select * from solotb_nivel3 ";  
$strSql .= " order by des";

$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
if(!$oConexion->EjecutarQuery($strSql)) {
    $strERROR=1;
    $err=0;
}
$arrData3=array();
$arrData3=$oConexion->getData("NUM");

$bEOF3=false;
if (empty($arrData3[0][1])) {
    $bEOF3=true;
}
$oConexion->Cerrar();

//'****************************** MAXIMO   
$strSql="select (max(id3)+1) as id  from solotb_nivel3";
//$strSql .= " where id2=" . $strid2;



$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
if (!$oConexion->EjecutarQuery($strSql)) {
    $strERROR=1;
    $err=0;
}
$MaxId=$oConexion->getData("NUM");
$MaxId= $MaxId[0][0];

if (is_null($MaxId)) {
    $MaxId=($strid2*100)+1;
}
$oConexion->Cerrar();
?>
<html>
    <head>
        <title>Documentacion</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT></head>

    <body topmargin=0 leftmargin=0>
        <p align="center" class="SoloStyle_TituloPaginas">Tabla de Categor&iacute;as</p>
        <form name="frmIngreso" action="trn_GrabaSubCategoria.php" method="POST">
            <table border="0" width="50%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta">C&oacute;digo</td>
                    <td><input name="hidId1" type="text" class="SoloStyle_Texto" value="<?php echo $MaxId;?>" size="40" readonly></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Nueva Categor&iacute;a</td>
                    <td><input name="ATxtDesc" type="text" class="SoloStyle_texto" id="ATxtDesc" size="40" maxlenght="50"></td>
                </tr>
            </table>
            <br><center>
                <input type="button" name="CmdGrabar" value="Grabar" class="SoloStyle_Boton" onClick="SoloFun_Submit(document.frmIngreso)"></center>
            <input type="hidden" name="opc" value="G">
        </form>
        <table width="50%" border="0" align="center">
            <tr class="SoloStyle_Etiqueta">
                <td class="texto">Categor&iacute;as</td>
                <td class="texto" width="20%">Acci&oacute;n</td>
            </tr>
            <?php for ($i=0;$i < count($arrData3);$i++) {
                $clase = "SoloStyle_Grid";
                if($i%2 > 0)
                    $clase = "SoloStyle_Texto";
                ?>

            <tr class="<?php echo $clase;?>">
                <td><?php echo $arrData3[$i][1];?></td>
                <td><a href="trn_GrabaSubCategoria.php?id3=<?php echo $arrData3[$i][0];?>&ds3=<?php echo $arrData3[$i][1];?>&opc=M">
                        <img src='iconos/soloico_modificar.gif' alt='Modificar' width="23" height="19" border='0' style='cursor:hand' ></a>
                    &nbsp;<a href="#" onClick="Comprobar('trn_GrabaSubCategoria.php?id3=<?php echo $arrData3[$i][0];?>&ds3=<?php echo $arrData3[$i][1];?>&opc=E')">
                        <img src='iconos/soloico_eliminar.gif' alt='Borrar Campos' width="23" height="19" border='0' style='cursor:hand'></a></td>
            </tr>
                <?php } ?>
        </table>
    </body>
</html>

<!--#include file="Includes/soloFun_ShowMessages.php"-->
<SCRIPT LANGUAGE="JavaScript" src="includes/fun_generales.js"></SCRIPT>

<script type="text/JavaScript">

    function Comprobar(pagina){
        var conf = confirm("Confirma Eliminar");
        if (conf)
            window.location.href = pagina;
    }

</script>